#include "Mathematica.h"
#include <vector>
#include <limits>

double Mathematica::minDistance2Point(size_t j, PointF s, const std::vector<PointF> & points)
{
	double distSquared = 0.0;

	double minDist = std::numeric_limits<double>::max();

	for (size_t i = 0; i < points.size(); i++)
	{
		if(i == j)
		{
			continue;
		}

		distSquared = pow(points[i].x - s.x, 2) + pow(points[i].y - s.y, 2);

		if(distSquared <= minDist)
		{
			minDist = distSquared;
		}
	}

	return sqrt(minDist);
}

double Mathematica::minDistance(const std::vector<PointF> & points)
{
	double dist = 0.0;

	double minDist = pow(points[1].x - points[0].x, 2) + pow(points[1].y - points[0].y, 2);

	for (size_t i = 0; i < points.size(); i++)
	{
		for (size_t j = 0; j < points.size(); j++)
		{
			if(i == j)
			{
				continue;
			}

			dist = pow( points[j].x - points[i].x, 2 ) + pow( points[j].y - points[i].y, 2 );

			if(dist < minDist)
			{
				minDist = dist;
			}
		}
	}

	return sqrt(minDist);
}